package com.snail.entity.mapper;

import com.snail.entity.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @Author 【swg】.
 * @Date 2017/12/12 10:28
 * @DESC
 * @CONTACT 317758022@qq.com
 */
public interface ProductCategoryMapper {
    /**插入指定的字段*/
    @Insert("insert into product_category(category_name,category_type) values(#{category_name,jdbcType=VARCHAR},#{category_type,jdbcType=INTEGER})")
    int insertByMap(Map<String,Object> map);

    /**插入对象*/
    @Insert("insert into product_category(category_name,category_type) values(#{categoryName,jdbcType=VARCHAR},#{categoryType,jdbcType=INTEGER})")
    int insertByObject(ProductCategory productCategory);

    /**根据指定的字段进行查询*/
    @Select("select * from product_category where category_type = #{categoryType}")
    @Results({
            @Result(column = "category_type",property = "categoryType")
    })
    ProductCategory findByCategoryType(Integer categoryType);

    /**根据指定的字段进行查询*/
    @Select("select * from product_category where category_name = #{categoryName}")
    @Results({
            @Result(column = "category_name",property = "categoryName")
    })
    List<ProductCategory> findByCategoryName(String name);

    /**根据指定的字段进行更新*/
    @Update("update product_category set category_name= #{categoryName} where category_type=#{categoryType}")
    int updateByCategoryType(@Param("categoryName") String categoryName,@Param("categoryType") Integer categoryType);

    /**根据对象进行更新*/
    @Update("update product_category set category_name= #{categoryName} where category_type=#{categoryType}")
    int updateByObject(ProductCategory productCategory);

    /**根据指定的字段进行删除*/
    @Delete("delete from product_category where category_type = #{categoryType}")
    int deleteByType(Integer categoryType);

    ProductCategory selectByCategoryType(Integer categoryType);
}
